package com.lzy.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.ProjectMapperExt;
import com.lzy.product.dtos.ProjectDto;
import com.lzy.product.entity.Project;
import com.lzy.product.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    ProjectMapperExt projectMapperExt;
    @Override
    public void add(ProjectDto projectDto) {
        Project project = DozerUtils.map(projectDto, Project.class);
        projectMapperExt.insertSelective(project);
    }

    @Override
    public PageInfo<ProjectDto> queryList(Pager pager, ProjectDto query) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(),pager.getPageSize());
        List<ProjectDto> projectDtos = projectMapperExt.queryList(query);
        return new PageInfo<>(projectDtos);
    }

    @Override
    public void delete(Long id) {
        projectMapperExt.deleteByPrimaryKey(id);
    }

    @Override
    public ProjectDto getById(Long id) {
       Project project =  projectMapperExt.selectByPrimaryKey(id);
        return DozerUtils.map(project, ProjectDto.class);
    }

    @Override
    public void update(ProjectDto projectDto) {
        projectMapperExt.updateByPrimaryKeySelective(DozerUtils.map(projectDto, Project.class));
    }

    @Override
    public List getList() {
        return projectMapperExt.getList();
    }

    @Override
    public List<ProjectDto> getList(ProjectDto dto) {
        return projectMapperExt.getProjectList(dto);
    }
}
